/*
 * @Author: xianfuyou
 * @Date: 2022-04-08 14:30:32
 * @LastEditors: your name
 * @LastEditTime: 2022-04-08 18:29:35
 * @Description: file content
 */
import Axios from "../../../utils/myAxios"



export function putOrderListsAction(data) {
  console.log(data)
  return { type: 'putOrderLists', data }
}
export function putOrderCount(data) {
  return { type: 'putCount', data }
}
// 获取当前订单信息
export function getOrderListsAction(data) {
  return (dispatch) => {
    Axios.post('/order/findOrderAll', data,
      { headers: { 'Content-Type': 'application/json' } }).then(res => {
        console.log(res)
        if (res.data.code === 200 && res.data.data) {
          const { count, orderList } = res.data.data
          let newOrderList = orderList.map((item) => {
            item['key'] = item.id
            return item
          })
          dispatch(putOrderListsAction(newOrderList))
          dispatch(putOrderCount(count))
        } else {
          dispatch(putOrderListsAction([]))
          dispatch(putOrderCount(0))
        }
      }).catch(err => {
        console.log(err)
      })
  }
}
export function putAllPriceAction(data) {
  return { type: 'putAllPrice', data }
}
// 获取汇总数据
export function getAllPriceAction(data) {
  // console.log('getAllPrice')
  return (dispatch) => {
    Axios.get('/order/findOrderTabulateStatistics')
      .then(res => {
        console.log(res)
        if (res.data.code === 200 && res.data.data) {
          const { orderMoney, collectMoney, arrearsMoney } = res.data.data
          // console.log(orderMoney, collectMoney, arrearsMoney)
          let resObj = { payAll: orderMoney, onPay: collectMoney, unOnPay: arrearsMoney }
          dispatch(putAllPriceAction(resObj))
          // setPriceAll(Object.assign({}, priceAll, { payAll: orderMoney, onPay: collectMoney, unOnPay: arrearsMoney }))
        }
      }).catch(err => {
        console.log(err)
      })
  }
}